home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / 8bit / diskutil / ibm2azip.new / ibm2a.c < prev    next >
C/C++ Source or Header  |  1993-04-03  |  7KB  |  170 lines

  1. /*
  2.  *************************************************************************
  3.  *
  4.  *  ibm2a.c -- convert from ASCII to ATASCII, with ATASCII graphics
  5.  *
  6.  *  by Bob Hardy, Feb-Apr 1993, v1.1
  7.  *
  8.  **************************************************************************
  9.  */
  10.  
  11. /*
  12.      Mat*Rat brought many useful and interesting programs to Atari BASIC,
  13.      and he also wrote some simple C programs for text processing, to convert
  14.      from/to the Atari EOL character to/from the IBM-PC CR/LF combination, in
  15.      the tradition of UNIX2DOS/DOS2UNIX.  While this code doesn't borrow much
  16.      from Mat*Rat, we take this opportunity to thank him for the good stuff
  17.      he brought us, particularly in the early '80's, and to admit that while
  18.      this program is more elaborate than his comparable programs, he was here
  19.      first.  Thanks Matt, and long may you Rat!
  20.  */      
  21.  
  22. /*
  23.      This program made necessary some unusual design decisions.  They
  24.      revolved around how to deal with the fact that ATASCII has character
  25.      "box" graphics, but has no double-line box characters, like the
  26.      IBM-PC character set.  In the end, I took the only reasonable course
  27.      that occurred to me -- since the PC has no inverse video box chars,
  28.      let's swap inverse video chars for double-line box chars!
  29.  */
  30.  
  31.  
  32. #include <stdio.h>
  33.  
  34. int main (int argc, char **argv[])
  35. {
  36.   FILE *infile, *outfile;
  37.   int c;
  38.  
  39.   puts("IBM2A - Convert ASCII to ATASCII, with Atari character graphics");
  40.   puts("by Bob Hardy, with acknowledgements to Mat*Rat\n");
  41.  
  42.   if (argc < 3) {
  43.     printf("Usage: %s infile outfile\n", argv[0]); 
  44.     exit(1);
  45.   }
  46.     if ((infile=fopen(argv[1], "rb")) == NULL) {
  47.     printf("%s: Could not open %s for read.\n", argv[0], argv[1]);
  48.     exit(1);
  49.   }
  50.   if ((outfile=fopen(argv[2], "wb")) == NULL) {
  51.     printf("%s: Could not open %s for write.\n", argv[0], argv[2]);
  52.     exit(1);
  53.   }
  54.   printf("Converting %s...\n", argv[1]);
  55.     while ((c=getc(infile)) != EOF) {
  56.     switch(c) {
  57.       case '\3'  : putc('\0',   outfile); /* heart */
  58.                    break;
  59.       case '\4'  : putc('\140', outfile); /* diamond */
  60.                    break;
  61.       case '\5'  : putc('\20',  outfile); /* club */
  62.                    break;
  63.       case '\6'  : putc('\173', outfile); /* spade */
  64.                    break;
  65.       case '\7'  : putc('\24',  outfile); /* big dot */
  66.                    break;
  67.       case '\10' : putc('\224', outfile); /* inverse big dot */
  68.                    break;
  69.       case '\11' : putc('\177', outfile); /* TAB */
  70.                    break;
  71.       case '\12' : putc('\233', outfile); /* CR = EOL */
  72.                    break;
  73.       case '\15' : break;                 /* Discard LF! */
  74.       case '\263': putc('\174', outfile); /* single vertical line */
  75.                    break;
  76.       case '\264': putc('\4',   outfile); /* single right T-junction */
  77.                    break;
  78.       case '\265': putc('\204', outfile); /* mixed right T-junction */
  79.                    break;
  80.       case '\266': putc('\204', outfile); /* mixed right T-junction */
  81.                    break;
  82.       case '\267': putc('\205', outfile); /* mixed upper right box char */
  83.                    break;
  84.       case '\270': putc('\205', outfile); /* mixed upper right box char */
  85.                    break;
  86.       case '\271': putc('\204', outfile); /* double right T-junction */
  87.                    break;
  88.       case '\272': putc('\374', outfile); /* double vertical line */
  89.                    break;
  90.       case '\273': putc('\205', outfile); /* double upper right box char */
  91.                    break;
  92.       case '\274': putc('\203', outfile); /* double lower right box char */
  93.                    break;
  94.       case '\275': putc('\203', outfile); /* mixed lower right box char */
  95.                    break;
  96.       case '\276': putc('\203', outfile); /* mixed lower right box char */
  97.                    break;
  98.       case '\277': putc('\5',   outfile); /* single upper right box char */
  99.                    break;
  100.       case '\300': putc('\32',  outfile); /* single lower left box char */
  101.                    break;
  102.       case '\301': putc('\30',  outfile); /* single inverted T-junction */
  103.                    break;
  104.       case '\302': putc('\27',  outfile); /* single vertical T-junction */
  105.                    break;
  106.       case '\303': putc('\1',   outfile); /* single left T-junction */
  107.                    break;
  108.       case '\304': putc('\22',  outfile); /* single horizontal line */
  109.                    break;
  110.       case '\305': putc('\23',  outfile); /* single 4-way junction */
  111.                    break;
  112.       case '\306': putc('\201', outfile); /* mixed left T-junction */
  113.                    break;
  114.       case '\307': putc('\201', outfile); /* mixed left T-junction */
  115.                    break;
  116.       case '\310': putc('\232', outfile); /* double lower left box char */
  117.                    break;
  118.       case '\311': putc('\221', outfile); /* double upper left box char */
  119.                    break;
  120.       case '\312': putc('\230', outfile); /* double inverted T-junction */
  121.                    break;
  122.       case '\313': putc('\227', outfile); /* double vertical T-junction */
  123.                    break;
  124.       case '\314': putc('\201', outfile); /* double left T-junction */
  125.                    break;
  126.       case '\315': putc('\222', outfile); /* double horizontal line */
  127.                    break;
  128.       case '\316': putc('\223', outfile); /* double 4-way junction */
  129.                    break;
  130.       case '\317': putc('\230', outfile); /* mixed inverted T-junction */
  131.                    break;
  132.       case '\320': putc('\230', outfile); /* mixed inverted T-junction */
  133.                    break;
  134.       case '\321': putc('\227', outfile); /* mixed vertical T-junction */
  135.                    break;
  136.       case '\322': putc('\227', outfile); /* mixed vertical T-junction */
  137.                    break;
  138.       case '\323': putc('\232', outfile); /* mixed lower left box char */
  139.                    break;
  140.       case '\324': putc('\232', outfile); /* mixed lower left box char */
  141.                    break;
  142.       case '\325': putc('\221', outfile); /* mixed upper left box char */
  143.                    break;
  144.       case '\326': putc('\221', outfile); /* mixed upper left box char */
  145.                    break;
  146.       case '\327': putc('\223', outfile); /* mixed 4-way junction */
  147.                    break;
  148.       case '\330': putc('\223', outfile); /* mixed 4-way junction */
  149.                    break;
  150.       case '\331': putc('\3',   outfile); /* lower right corner */
  151.                    break;
  152.       case '\332': putc('\21',  outfile); /* single upper left box char */
  153.                    break;
  154.       case '\334': putc('\16',  outfile); /* low horizontal bar */
  155.                    break;
  156.       case '\335': putc('\26',  outfile); /* left vertical bar */
  157.                    break;
  158.       case '\336': putc('\2',   outfile); /* right vertical bar */
  159.                    break;
  160.       case '\337': putc('\15',  outfile); /* high horizontal bar */
  161.                    break;
  162.       default    : putc(c, outfile);      /* Accept given character. */
  163.                    break;
  164.     }
  165.   }
  166.   fclose(outfile);
  167.   printf("%s: End-of-file encountered.\n", argv[1]);
  168.   exit(0);
  169. }
  170.